package com.pk.platform.business.core.web;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.struts2.ServletActionContext;

import com.pk.platform.util.StringConverter;

public class DownloadAction extends GenericAction {

	private String absoluteFilePath;

	private String relativeFilePath;
	
	private InputStream fileStream;
	
	public String download() throws Exception
	{
		if(StringConverter.isNotNull(relativeFilePath))
		{
			fileStream = ServletActionContext.getServletContext().getResourceAsStream("/" + relativeFilePath);
		}
		else if(StringConverter.isNotNull(absoluteFilePath))
		{
			fileStream = new FileInputStream(absoluteFilePath);
		}
		return FILE;
	}
	
	public String getAbsoluteFilePath() {
		return absoluteFilePath;
	}
	
	public void setAbsoluteFilePath(String absoluteFilePath) {
		this.absoluteFilePath = absoluteFilePath;
	}
	
	public String getRelativeFilePath() {
		return relativeFilePath;
	}
	
	public void setRelativeFilePath(String relativeFilePath) {
		this.relativeFilePath = relativeFilePath;
	}

	public InputStream getFileStream() {
		return fileStream;
	}

	public void setFileStream(InputStream fileStream) {
		this.fileStream = fileStream;
	}
	
}
